from rest_framework import serializers

from game import models


class CategorySerializer(serializers.ModelSerializer):

    class Meta:
        model = models.GameCategory
        fields = '__all__'


class GameSerializer(serializers.ModelSerializer):
    category_info = CategorySerializer(source='category', read_only=True)

    class Meta:
        model = models.Game
        fields = [
            'id',
            'name',
            'category',
            'vendors',
            'platform',
            'size',
            'version',
            'state',
            'create_time',
            'update_time',
            'category_info'
        ]

    def get_category_info(self, obj):
        return obj.category.name
